
//
//  DB.m
//  chanyou
//
//  Created by leon on 15/1/9.
//  Copyright (c) 2015年 wanli. All rights reserved.
//

#import "DB.h"
#import <sqlite3.h>

static sqlite3 *dbPoint = nil;

@implementation DB

+ (sqlite3 *)openDB
{
    if (dbPoint) {
        return dbPoint;
    }
    
    NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [array firstObject];
    path = [NSString stringWithFormat:@"%@/travels.db", path];
    NSLog(@"%@", path);
    NSFileManager *manager = [NSFileManager defaultManager];
    if (![manager fileExistsAtPath:path]) {
        NSString *source = [[NSBundle mainBundle] pathForResource:@"travelsDB" ofType:@"rdb"];
        [manager copyItemAtPath:source toPath:path error:nil];
    }
    sqlite3_open([path UTF8String], &dbPoint);
    return dbPoint;
}


@end
